# coding:utf-8

"""
__title__ = ''
__author__ = 'qwen'
__mtime__ = '2019/11/18'

"""
from __future__ import division
import appconf,json
from flask import render_template, request
import httpLoad.loadRoute
import httpApi.apiRoute
import caseManage.baseCaseRoute
import caseManage.casePlanRoute
import UserManage.userRoute
import UserManage.userBussiness
import httpApi.apiBussiness
import caseManage.baseCaseBussiness
import caseManage.casePlanBussiness


app=appconf.app

@app.route('/load/index')
def load_index():
    return render_template('loadIndex.html')

@app.route('/load/add')
def load_add():
    return render_template('loadAdd.html')

@app.route('/load/result')
def load_result():
    return render_template('loadResult.html')


@app.route('/load/result/history')
def load_result_history():
    return render_template('loadResultHistory.html')

@app.route('/load/result/history/remark')
def load_result_history_remark():
    return render_template('loadResultRemark.html')

################################################################################
@app.route('/api/case/index')
def api_case_index():
    # projectAllName = json.loads(httpApi.apiRoute.project_all_select()).get('data')
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token,openId)

    return render_template('apicaseIndex.html',projectAll = projectAllName,token=token,openId=openId)

@app.route('/api/case/manage')
def api_case_manage():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('apicaseManage.html',projectAll = projectAllName)

@app.route('/api/case/params/index')
def api_case_params_index():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('apicaseParamIndex.html',projectAll = projectAllName,token=token,openId=openId)

@app.route('/api/case/params/manage')
def api_case_params_manage():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('apicaseParamManage.html',projectAll = projectAllName)

@app.route('/api/case/result/index')
def api_case_result_index():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('apicaseResultIndex.html',projectAll = projectAllName)

@app.route('/api/case/result/history/index')
def api_case_result_history_index():
    projectAllName = json.loads(httpApi.apiRoute.project_all_select()).get('data')
    return render_template('apicaseResultHistory.html',projectAll = projectAllName)

@app.route('/project/index')
def project_index():
    return render_template('projectIndex.html')


@app.route('/project/manage')
def project_index_manage():
    return render_template('projectManage.html')

@app.route('/moudle/index')
def moudle_index():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('moudleIndex.html',projectAll = projectAllName,token=token,openId=openId)

@app.route('/moudle/index/manage')
def moudle_index_manage():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)
    return render_template('moudleManage.html',projectAll = projectAllName)


@app.route('/case/plan/index')
def case_plan_index():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('apicasePlanIndex.html',projectAll = projectAllName,token=token,openId=openId)

@app.route('/case/plan/manage')
def case_plan_manage():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)
    return render_template('apicasePlanManage.html',projectAll = projectAllName)

###############################################################################
@app.route('/basecase/index/1')
def basecase_index_1():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('baseIndex.html',projectAll = projectAllName)

@app.route('/basecase/index/manage')
def basecase_manage_1():
    return render_template('baseMoreManage.html')


@app.route('/basecase/do/index')
def basecase_do():
    token = request.args.get("token")
    openId = request.args.get("openId")
    userId = UserManage.userBussiness.getUserId(token,openId, t=0)
    data = caseManage.baseCaseBussiness.baseCase_gotMyDo(userId, None)
    return render_template('baseCaseDoIndex.html',AllTaskName = data)

@app.route('/basecase/do/history')
def basecase_do_history():
    case_id = request.args.get("case_id")
    resultId = request.args.get("resultId")

    return render_template('caseResultTime.html',resultId=resultId,case_id=case_id)


@app.route('/basecase/import/index')
def basecase_import():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('basecaseImport.html',projectAll = projectAllName)


@app.route('/basecase/case/hisResult')
def basecase_hisResult():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('caseResultHistory.html',projectAll = projectAllName)

@app.route('/basecase/case/hisResult/sys')
def basecase_hisResult_sys():
    token = request.args.get("token")
    openId = request.args.get("openId")
    projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)

    return render_template('caseResultSys.html',projectAll = projectAllName)

###################################################################################
@app.route('/casePlan/index')
def casePlan_index():
    # token = request.args.get("token")
    # openId = request.args.get("openId")
    # projectAllName = httpApi.apiBussiness.project_select_all_byUserId(token, openId)
    projectAllName = json.loads(httpApi.apiRoute.project_all_select()).get('data')
    return render_template('casePlanIndex.html',projectAll = projectAllName)

@app.route('/casePlan/main/manage')
def casePlan_main_manage():
    projectAllName = json.loads(httpApi.apiRoute.project_all_select()).get('data')
    userAll = json.loads(UserManage.userRoute.userInfo_all()).get('data')
    return render_template('casePlanMainManage.html',projectAll = projectAllName,userAll=userAll)


@app.route('/casePlan/main/process')
def casePlan_main_process():
    return render_template('casePlanProcess.html')


@app.route('/casePlan/sub/manage')
def casePlan_sub_manage():
    userAll = json.loads(UserManage.userRoute.userInfo_all()).get('data')
    return render_template('casePlanSubManage.html',userAll=userAll)

@app.route('/casePlan/sub/index')
def casePlan_sub_index():
    return render_template('casePlanSubIndex.html')

##################################################
@app.route('/user/index')
def user_index():
    return render_template('userIndex.html')

@app.route('/user/manage')
def user_manage():

    return render_template('userManage.html')

@app.route('/index')
def index():
    #   只在这里控制accessToken和openId的合法性
    token = request.args.get("token")
    openId = request.args.get("openId")

    winWidth = request.args.get("winWidth")
    winHeight = request.args.get("winHeight")

    if UserManage.userBussiness.getUserId(token,openId):
        return render_template('index.html',token=token,openId=openId,winHeight=winHeight,winWidth=winWidth)
    return render_template('login.html')

@app.route('/login')
def login():
    return render_template('login.html')

@app.route('/totalHtml')
def test():
    token = request.args.get("token")
    openId = request.args.get("openId")
    userId = UserManage.userBussiness.getUserId(token, openId)
    myData = caseManage.casePlanBussiness.case_sys_total_byme(userId)

    return render_template('totalHtml.html',ALLMyData=myData)

if __name__ == '__main__':
    # pass
    import httpApi.apiPlanRun

    httpApi.apiPlanRun.back_runJob()

    app.run(host='0.0.0.0', port=9012, debug=True)

